import { Public } from '@libs/common/decorator';
import { BusinessException } from '@libs/common/exceptions';
import { Body, Controller, Get, Post, Query } from '@nestjs/common';

import { AuthService } from './auth.service';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Post('login')
  @Public()
  async loginPost(@Body() dto: { code: string }) {
    if (!dto.code || typeof dto.code !== 'string') {
      throw new BusinessException('code 参数不合法');
    }

    return this.authService.login(dto.code);
  }
}
